/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utn.tsb.tej.world_logic;

import csm.uttils.generics.Roster;

/**
 *
 * @author Administrador
 */
public class ObjectiveConquer extends Objective  {

    private Continent continent;
    private int numbreOfCountries;

    public ObjectiveConquer(int number, Continent continen, int numbreOfCountries) {
        super(number);
        this.continent = continen;
        this.numbreOfCountries = numbreOfCountries;
    }

    public Continent getContinent() {
        return continent;
    }

    public void setContinent(Continent continent) {
        this.continent = continent;
    }

    public int getNumbreOfCountries() {
        return numbreOfCountries;
    }

    public void setNumbreOfCountries(int numbreOfCountries) {
        this.numbreOfCountries = numbreOfCountries;
    }

    public Player getOwner() {
        Roster<Player> players = WorldLogicFacade.world.getRounds().getLast().getTurns();
        Player player = null;
        for (int i = 0; i < players.count(); i++) {
            player = players.getElementInPosition(i);
            if (player.getObjectives().indexOf(this) != -1) {
                break;
            }
        }
        return player;
    }

    @Override
    public boolean isAccomplished() {
        boolean accomplished = false;
        int conquered=0;
        Roster<Country> continentCountries = continent.getCountries();
        for (int i = 0; i < continentCountries.count(); i++) {
            if(getOwner().getCountries().indexOf(continentCountries.getElementInPosition(i))!=-1){
                conquered++;
            }
        }
        if(conquered>=numbreOfCountries){
            accomplished=true;
        }
        return accomplished;
    }

    public String toString(){
        return "Conquistar " + numbreOfCountries + " paises de " + continent.getName();
    }
}
